package com.health.httpbean.format;

import android.text.TextUtils;

import com.blankj.utilcode.util.TimeUtils;
import com.health.httpbean.model.GxbBean;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.webservice.CoronaryHeartDisease;
import com.health.viewscontrols.NovaApplication;

import net.tsz.afinal.db.sqlite.DbModel;

import java.util.List;

import static com.health.httpbean.format.FormatUtils.formatAskSymptom;
import static com.health.httpbean.format.FormatUtils.parseDouble;
import static com.health.httpbean.format.FormatUtils.parseInt;

/**
 * author : xiaoxin
 * date   : 2020/12/17 22:35
 * desc   : 冠心病
 * update :
 */
public class FormatGxbData {

    public static GxbBean formatGxb(CoronaryHeartDisease table, List<BD_DD_INFO> listZZs) {
        GxbBean bean = new GxbBean();

        try {
            bean.CardID = table.getCardid();
//        bean.ID_UserDocument = table.getPersonalid();
            String userSql = "SELECT * FROM ARCHIVE_BASEINFO WHERE IDCARD = '" + table.getCardid() + "'";
            DbModel userModel = NovaApplication.fdbmanger.findDbSql(userSql);
            bean.UserName = userModel.getString("CUSTOMERNAME");
            bean.BianHao = table.getCoronaryCardid();
            bean.SuiFangRiQi = table.getHappentime();
            try {
                String zhuanzhenSql = "SELECT * FROM HdPersonalRollOut WHERE item0 = '" + table.getId() + "'";
                DbModel zhuanzhenModel = NovaApplication.fdbmanger.findDbSql(zhuanzhenSql);
                if (zhuanzhenModel != null) {
                    bean.ZhuanZhenYuanYin = zhuanzhenModel.getString("hpc");
                    //有无转诊   DM01-11_2 有 DM01-11_1 无
                    if (!TextUtils.isEmpty(zhuanzhenModel.getString("hpc"))) {
                        bean.ZhuanZhenQingKuang = 2;
                    }else {
                        bean.ZhuanZhenQingKuang = 1;
                    }
                    bean.ZhuanZhenJiGou = zhuanzhenModel.getString("rollInRegion");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            bean.XiaCiSuiFangRiQi = table.getNextVisitDate();

            bean.SuiFangDoctorName = table.getInputMan();
            //没有随访类型
            bean.SuiFangLeiXing = FormatUtils.parseInt(table.getVisitType());
            bean.SuiFangFangShi = parseInt(table.getVisitWay());
//        bean.InputerName = parseInt(table.getin());
            bean.ZhengZhuang = formatAskSymptom(table.getCurSymptom(),listZZs);
            bean.ZhengZhuangQiTa = table.getOtherSymptom();
            bean.RBloodUp = parseInt(table.getPressureH());
            bean.RBloodDown = parseInt(table.getPressureL());
            bean.WL = parseDouble(table.getAvoirdupois());
            bean.WLMuBiao = parseDouble(table.getTargetAvoirdupois());
            bean.BMI = parseDouble(table.getPhysique());
            bean.BMIMuBiao = parseDouble(table.getTargetPhysique());
            bean.HR = parseInt(table.getPulseRate());
            bean.TiZhengQiTa = table.getOtherPositive();
            bean.Smoke = table.getSmoke();
            bean.SmokeMuBiao = table.getTargetSmoke();
            bean.Drink = table.getDrink();
            bean.DrinkMuBiao = table.getTargetDrink();
            bean.SportsWeeks = table.getTraining();
            bean.SportsWeeksMuBiao = table.getTargetTraining();
            bean.SportsTimes = table.getTrainingMin();
            bean.SportsTimesMuBiao = table.getTargetTrainingMin();
            bean.SheYan = parseDouble(table.getSalt());
            bean.SheYanMuBiao = parseDouble(table.getTargetSalt());
            bean.XinLiTiaoZheng = parseInt(table.getMentality());
            bean.ZunYiXingWei = parseInt(table.getCompiance());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return bean;
    }
}
